package com.sxtyxt.online.me;

import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.sxtyxt.entity.ResultVo;
import com.sxtyxt.online.ActBase;
import com.sxtyxt.online.R;
import com.sxtyxt.online.SystemConst;
import com.sxtyxt.util.GsonUtil;
import com.sxtyxt.util.UIUtil;
import com.sxtyxt.volley.LoadingDialogResultListenerImpl;
import com.sxtyxt.volley.URL;
import com.sxtyxt.volley.VolleyUtils;

/**
 * 重置密码
 * Created by General on 15/8/26.
 */
public class ActResetPwd extends ActBase {

    private EditText etxtNew, etxtNewConfirm;
    private String memberId;
    @Override
    protected int getLayoutId() {
        return R.layout.reset_pwd;
    }

    @Override
    protected void initUI() {
        super.initUI();
        memberId = getIntent().getStringExtra("memberId");
        etxtNew = (EditText) findViewById(R.id.etxt_new_pwd);
        etxtNewConfirm = (EditText) findViewById(R.id.etxt_new_pwd_confirm);
        UIUtil.screenCopyAndPaste(etxtNew);
        UIUtil.screenCopyAndPaste(etxtNewConfirm);
        mTitleBar.mSetOnRightButtonClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (TextUtils.isEmpty(getStringByUI(etxtNew))) {
                    doToast("新密码不能为空");
                    return;
                }
                if (!getStringByUI(etxtNew).equals(getStringByUI(etxtNewConfirm))) {
                    doToast("两次输入的密码不一致");
                    return;
                }
                requestService();
            }
        });
    }

    private void requestService() {
        VolleyUtils.requestService(SystemConst.MODIFY_PWD, URL.modifyPwd(getStringByUI(etxtNewConfirm), "", memberId), new LoadingDialogResultListenerImpl(this, "正在重置密码") {
            @Override
            public void onSuccess(String response) {
                super.onSuccess(response);
                ResultVo<?> vo = GsonUtil.deser(response, ResultVo.class);
                if (vo == null) {
                    return;
                }
                if (vo.getResult() == 1) {
                    doToast("修改成功");
                    finish();
                } else {
                    doToast(vo.getMsg());
                }
            }

            @Override
            public void onError() {
                super.onError();
            }
        });
    }


}
